/****************************************************
          File Name:array_sequence_queue.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 09 Feb 2015 09:22:27 PM CST
*****************************************************/

#ifndef sequence_queue_
#define sequence_queue_

#include <stdbool.h>
//算法复杂度 O(n)

#define QUEUE_MAX   5
typedef int mydata;

typedef struct QUEUE
{
    mydata data[QUEUE_MAX];
    int front;
    int rear;
} Queue;

void InitQueue(Queue *q)
{
    q->front = 0;
    q->rear = 0;
}

bool isFull(Queue *q)
{
    return q->rear == QUEUE_MAX ? true : false;
}

bool isEmpty(Queue *q)
{
    return q->front == q->rear ? true : false;
}

bool EnQueue(Queue *q, mydata e)
{
    if(isFull(q)) return false;

    q->data[q->rear] = e;
    q->rear++;
    return true;
}

bool DeQueue(Queue *q, mydata *e)
{
    if(isEmpty(q)) return false;

    *e = q->data[q->front];
    for(int i=0; i<q->rear; i++)
        q->data[i] = q->data[i+1];
    q->rear--;
    return true;
}

int QueueLength(Queue *q)
{
    return q->rear;
}

#endif
